# == Schema Information
#
# Table name: product_properties
#
#  id         :integer          not null, primary key
#  product_id :integer
#  item_type  :string
#  item_value :string
#  created_at :datetime         not null
#  updated_at :datetime         not null
#


class ProductProperty < ApplicationRecord
  belongs_to :product

  class << self

    def find_or_init_properties product_id
      product = Product.find_by_id product_id
      if product.present?
        product.properties
      else
        %W(产品型号 扇价 安装费 品类 开启方式 型材壁厚 玻璃配置 配件 免费颜色).inject([]) do |result, item|
          result << ProductProperty.new(item_type: item, item_value: nil)
        end
      end
    end

  end
end
